/*
 * @Description: 登录 / 退出
 * @Author: DHL
 * @Date: 2021-12-31 14:52:24
 * @LastEditors: DHL
 * @LastEditTime: 2024-01-10 09:17:07
 */
import { LoginUserResultModel } from './model/loginModel'
import { ContentTypeEnum, RequestParams } from '@/constant/http'
import { Result } from '@/model/baseModel'
import { $post, $get } from '@/utils/http'

/**
 * 登录
 * @param params
 * @returns
 */
export const apiLogin = (params: RequestParams) =>
  $post<LoginUserResultModel>({
    url: '/sys/auth/login',
    params: params,
    contentType: ContentTypeEnum.form
  })

/**
 * 刷新登录用户缓存
 * @returns
 */
export const apiLoginRefreshCache = () =>
  $get<LoginUserResultModel>({
    url: '/sys/auth/refreshLoginUserCache'
  })

/**
 * 通过token登录
 */
export const apiLoginByToken = () =>
  $post<LoginUserResultModel>({
    url: '/sys/auth/loginByToken'
  })

/**
 * 通过token 字符串登录
 * @returns
 */
export const apiLoginByTokenStr = (token: string) =>
  $post<LoginUserResultModel>({
    url: '/sys/auth/loginByTokenStr',
    contentType: ContentTypeEnum.form,
    params: {
      token: token
    }
  })

/**
 * 退出登录
 * @returns
 */
export const apiLogOut = () =>
  $post<Result<string>>({
    url: '/sys/auth/logOut'
  })

/**
 * 查询登录用户信息
 * @returns
 */
export const apiGetLoginUserCache = () =>
  $get<LoginUserResultModel>({
    url: '/sys/auth/getLoginUserCache'
  })

/**
 * 切换登录用户租户
 * @param tenantId
 * @returns
 */
export const apiSwitchLoginUserTenant = (tenantId: string) =>
  $get<LoginUserResultModel>({
    url: '/sys/auth/switchTenant',
    params: {
      tenantId: tenantId
    }
  })
